/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace Madason.MetaModel.Interfaces.Tests
{

	[TestFixture]
	public class TestImportStarUmlStatemachine : TestImportStarUmlBase
	{
		Model model = null;
		Class testClass = null;

		[SetUp]
		public void Setup()
		{
			model = LoadModelFromResource("StatechartTestModel.uml");
			testClass = model.FindClassByName("Tests.TestClass");
		}
		
		[Test]
		public void TestStatemachine()
		{
			Assert.AreEqual(1, testClass.StateMachines.Count);
			Assert.AreEqual("Workflow", testClass.StateMachines[0].Name);
		}

		[Test]
		public void TestChildStates()
		{
			StateMachine sm = testClass.StateMachines[0];
			Assert.AreEqual(4, sm.States.Count);
		}

		[Test]
		public void TestStateNames()
		{
			StateMachine sm = testClass.StateMachines[0];

			Assert.AreEqual(4, sm.States.Count);
			Assert.IsNotNull(sm.States["Initial1"]);
			Assert.IsNotNull(sm.States["Created"]);
			Assert.IsNotNull(sm.States["Choice1"]);
			Assert.IsNotNull(sm.States["FinalState1"]);
		}

		[Test]
		public void TestStateTypes()
		{
			StateMachine sm = testClass.StateMachines[0];

			Assert.AreEqual(4, sm.States.Count);

			Assert.AreEqual(StateType.Initial, sm.States["Initial1"].StateType);
			Assert.AreEqual(StateType.Simple, sm.States["Created"].StateType);
			Assert.AreEqual(StateType.Branch, sm.States["Choice1"].StateType);
			Assert.AreEqual(StateType.Final, sm.States["FinalState1"].StateType);
		}

		[Test]
		public void TestTransition()
		{			
			StateMachine sm = testClass.StateMachines[0];

			State initial = sm.States["Initial1"];
			Assert.AreEqual(1, initial.Transitions.Count);
			Assert.AreEqual("FirstTransition", initial.Transitions[0].Name);
		}

		[Test]
		public void TestTransitionSource()
		{
			StateMachine sm = testClass.StateMachines[0];

			State initial = sm.States["Initial1"];
			Assert.AreEqual(1, initial.Transitions.Count);
			Assert.AreEqual(initial, initial.Transitions[0].Source);
		}


		[Test]
		public void TestTransitionTarget()
		{
			StateMachine sm = testClass.StateMachines[0];

			State initial = sm.States["Initial1"];
			State created = sm.States["Created"];

			Assert.AreEqual(1, initial.Transitions.Count);
			Assert.AreEqual(created, initial.Transitions[0].Target);
		}

		[Test]
		public void TestTransitionTrigger()
		{
			StateMachine sm = testClass.StateMachines[0];

			State created = sm.States["Created"];
			Assert.AreEqual(1, created.Transitions.Count);
			Assert.AreEqual(1, created.Transitions[0].Trigger.Count);
		}

		[Test]
		public void TestStateActions()
		{
			StateMachine sm = testClass.StateMachines[0];
			State created = sm.States["Created"];

			Assert.AreEqual(1, created.EntryActions.Count);
			Assert.AreEqual(1, created.ExitActions.Count);

			Assert.AreEqual("EntryAction1", created.EntryActions[0].Name);
			Assert.AreEqual("ExitAction1", created.ExitActions[0].Name);
		}

		[Test]
		public void TestTransitionAction()
		{
			StateMachine sm = testClass.StateMachines[0];
			State created = sm.States["Created"];

			Assert.AreEqual(1, created.Transitions[0].Actions.Count);
			Assert.AreEqual("Effect1", created.Transitions[0].Actions[0].Name);
		}


		[Test]
		public void TestTransitionGuard()
		{
			StateMachine sm = testClass.StateMachines[0];
			State choice1 = sm.States["Choice1"];
			Assert.AreEqual("TestGuard", choice1.Transitions[0].Guard);
		}

		[Test]
		public void TestStatemachineDirectInNamespace()
		{
			Namespace ns = model.Namespaces[0];
			Assert.AreEqual(1, ns.Statemachines.Count);
		}
	}
}
